博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP如何输出合并单元格的表
阅读量:6004 次
发布时间:2019-06-20

本文共 9119 字,大约阅读时间需要 30 分钟。

https://mp.weixin.qq.com/s/ChPIKIv9tqmuqGyfc9Zi7Q

合并单元格的表,很多地方可以见到,比如购物车,订单合并等,今天给大家讲解一下,如何操作,虽然我用的laravel,但是都是PHP。以下只做参考!

 

部分效果图如下

路由文件

 Route::get('admin/allots/index', ['as'=> 'admin.allots.index', 'uses' => 'AllotController@index']); 

控制器文件:AllotController.php

/**     * Display a listing of the Allot.     *     * @param Request $request     * @return Response     */    public function index(Request $request)    {        $param  = $request->all();        $params  = [            'orderBy' => ['allot_id', 'desc'],            'groupBy' => 'allot_sn'        ];        $params['left_join'][] = ['allot_detail','allot.allot_id','=','allot_detail.allot_id'];        $params['left_join'][] = ['goods_sku','allot_detail.sku_id','=','goods_sku.sku_id'];        $params['left_join'][] = ['goods','goods_sku.goods_id','=','goods.goods_id'];        $params['select']   = [            'allot.*',            'allot_detail.sku_id',            'goods_sku.sku_id',            'goods_sku.goods_id',            'goods.goods_id',            'goods.goods_name'        ];        if(!empty($param['goods_name'])){            $params['where'] = $this->entryWareRepository->getLikeGoods(trim($param['goods_name']));            $search_sku_id = $this->entryWareRepository->getLikeSkuID(trim($param['goods_name']));        }        //用户所属对应仓库的信息        $admin_ware = $this->allotRepository->getAdminWare();        if($admin_ware > 0){            $params['whereIn'] = ['allot.from_ware_id', $admin_ware];        }        $this->allotRepository->pushCriteria(new RequestCriteria($request));        $allots = $this->allotRepository->paginate(config('config.pagesize'),[            'detail.sku.goods','out_ware','entry_ware'        ],$params);        $allots->each(function($item,$key){            $item->is_out_ware = count($this->allotRepository->out_ware($item->allot_sn));            $item->is_entry_ware = count($this->allotRepository->entry_ware($item->allot_sn));        });        foreach ($allots as $val){            $val->detail->each(function($vo,$k){                $vo->change_sku = $vo->sku->getShowSku();            });        }        //dd($allots);        return view('admin.allots.index', compact('allots','admin_ware','param'));    }

model文件:Allot.php

class Allot extends Model{    public $table = 'allot';    const CREATED_AT = 'created_at';    const UPDATED_AT = 'updated_at';    protected $primaryKey = 'allot_id';    public $fillable = [        'allot_sn',        'remark',        'status',        'from_ware_id',        'to_ware_id',        'create_admin_id',        'create_admin_name',        'examine_admin_id',        'examine_admin_name',        'entry_ware_status',        'out_ware_status',        'confirm_admin_id',        'confirm_admin_name'    ];    /**     * The attributes that should be casted to native types.     *     * @var array     */    protected $casts = [        'allot_id' => 'integer',        'allot_sn' => 'string',        'remark' => 'string',        'status' => 'integer',        'from_ware_id' => 'integer',        'to_ware_id' => 'integer',        'create_admin_id' => 'integer',        'create_admin_name' => 'string',        'examine_admin_id' => 'integer',        'examine_admin_name' => 'string',        'confirm_admin_id' => 'integer',        'confirm_admin_name' => 'string',        'entry_ware_status' =>'integer',        'out_ware_status' => 'integer',    ];    /**     * Validation rules     *     * @var array     */    public static $rules = [    ];

容器文件:AllotRepository.php

model(); $model = new $model; $rs = $model; if (!empty($param['goods_name'])) { $rs = $model->where('goods_name', '=', $param['goods_name']); } //创建时间开始 if (!empty($param['add_time_start'])) { $rs = $rs->where('created_at', '>=', $param['created_at'] . ' 00:00:00'); } //创建时间结束 if (!empty($param['add_time_end'])) { $rs = $rs->where('created_at', '<=', $param['created_at'] . ' 23:59:59'); } return $rs; } /** * Function:自动生成入单号 * User:wucy * @return string */ public function createAllotSn() { $model = $this->model(); $allot_id = $model::max('allot_id'); $date = date('Ymd',time()); $allot_id = $allot_id +1; $allot_sn = 'A' .$date. str_repeat('0', 8 - strlen($allot_id)) . $allot_id; $sn_list = $model::where('allot_sn','like','%'.$allot_id.'%')->where('allot_id','<>',$allot_id)->get()->toArray(); if (in_array($allot_sn, $sn_list)) { $max = pow(10, strlen($sn_list[0]) - strlen($allot_sn) + 1) - 1; $new_sn = $allot_sn . mt_rand(0, $max); while (in_array($new_sn, $sn_list)) { $new_sn = $allot_sn . mt_rand(0, $max); } $allot_sn = $new_sn; } return $allot_sn; }

模板文件table.blade.php

@foreach($allots as $allot)
detail->whereInLoose('sku_id',$search_sku_id); }else{ $detail = $allot->detail; } $count = count($detail); $rowspan = $count == 1 ? '' : "rowspan='{
$count}'"; //单元格合并 $first_detail = $detail->shift(); $admin_id = Auth::id(); if(($admin_ware > 0 && in_array( $allot->from_ware_id,$admin_ware)) || $admin_ware==0){ $from_admin_ware =1; }else{ $from_admin_ware =0; } if(($admin_ware > 0 && in_array( $allot->to_ware_id,$admin_ware)) || $admin_ware==0){ $to_admin_ware =1; }else{ $to_admin_ware =0; } //dd($from_admin_ware); ?>
@if($rowspan != '') @foreach($detail as $row)
@endforeach @endif @endforeach
调拨单号 制单时间 调出仓库 商品SKU 商品名称 商品属性 单位 调拨数量 调入仓库 调拨备注 审核状态 审核人 是否出库 是否入库 操作
{!! $allot->allot_sn !!} {!! $allot->created_at !!} {!! $allot['out_ware']['name'] !!} {!! !empty($first_detail) ? $first_detail->change_sku : '--' !!} {!! !empty($first_detail) ? $first_detail->sku->goods->goods_name : '--' !!} {!! !empty($first_detail) ? $first_detail->sku->value_name : '--' !!} {!! !empty($first_detail) ? $first_detail->sku->goods->goods_unit : '--' !!} {!! !empty($first_detail) ? $first_detail->send_number : '--' !!} {!! $allot['entry_ware']['name'] !!} {!! $allot->remark !!} {!! config('const.ware.entry_status')[$allot->status] !!} {!! $allot->confirm_admin_name ? $allot->confirm_admin_name : '--'!!} {!! config('const.ware.entry_or_out_ware')[$allot->out_ware_status] !!} {!! config('const.ware.entry_or_out_ware')[$allot->entry_ware_status] !!} { !! Form::open(['route' => ['admin.allots.destroy', $allot->getKey()], 'method' => 'delete']) !!}
{ !! Form::close() !!}
{ { $row->change_sku }} { { $row->sku->goods->goods_name }} { { $row->sku->value_name }} { { $row->sku->goods->goods_unit }} { { $row->send_number }}

一个功能模块包括增删改查,贴出来的代码会很多!这里只贴出列表的功能,有问题的可以留言

转载地址:http://egbmx.baihongyu.com/

你可能感兴趣的文章
Nexpose
查看>>
java 获取URL链接 内容
查看>>
Dynamo涉及的算法和协议——p2p架构,一致性hash容错+gossip协议获取集群状态+向量时钟同步数据...
查看>>
【高并发解决方案】2、集群概述
查看>>
opengl 矩阵变换
查看>>
Linux 命令详解(二)awk 命令
查看>>
Android动态载入Dex机制解析
查看>>
PostgreSQL数据库中的常见错误
查看>>
jquery 控制 video 视频播放和暂停
查看>>
XCode调试多线程遭遇海森伯效应一例
查看>>
ie6下浮动使绝对定位元素莫名消失的问题
查看>>
FBReaderJ 1.6.3 发布,Android 电子书阅读器
查看>>
从头写一个Cucumber测试(一) Selenium Test
查看>>
Java编程常见问题汇总(四)
查看>>
Hadoop 学习系列(四)之 MapReduce 原理讲解
查看>>
函数throttle、debounce介绍
查看>>
源码阅读:SDWebImage(三)——NSData+ImageContentType
查看>>
十六、类的真正形态
查看>>
spring-cloud Sleuth
查看>>
Python 进阶之路 (十一) 再立Flag, 社区最全的itertools深度解析(下)
查看>>